package com.bestcem.xm.qdes.util;

import cn.hutool.core.util.StrUtil;
import com.bestcem.xm.component.mybatis.base.ResultPage;
import com.bestcem.xm.component.mybatis.constants.MybatisConstant;
import lombok.experimental.UtilityClass;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName: PageUtils
 * @Description:
 * @Author: chenglong.yue
 * @Date: 2022/8/2 10:40
 */
@UtilityClass
public class PageUtil {

    public <T> ResultPage<T> getResultPage(Number current, Number total, List<T> data) {
        ResultPage<T> ret = new ResultPage<>();
        ret.setPage(current);
        ret.setTotal(total);
        ret.setData(data);
        return ret;
    }

    /**
     * 从url字符串判断get请求是否要分页
     *
     * @param request
     * @return boolean
     * @author chenglong.yue <chenglong.yue@idiaoyan.com>
     * @date 2022/8/22 9:45
     */
    public boolean isPageQuery(HttpServletRequest request) {
        String querystr = request.getQueryString();
        if (StrUtil.isBlank(querystr)) {
            return false;
        }
        return querystr.contains(MybatisConstant.PAGE_KEY) || querystr.contains(MybatisConstant.ROWSPERPAGE_KEY);
    }
}
